package com.xwyzsn.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xwyzsn.common.annotation.Log;
import com.xwyzsn.common.core.controller.BaseController;
import com.xwyzsn.common.core.domain.AjaxResult;
import com.xwyzsn.common.enums.BusinessType;
import com.xwyzsn.system.domain.Stall;
import com.xwyzsn.system.service.IStallService;
import com.xwyzsn.common.utils.poi.ExcelUtil;
import com.xwyzsn.common.core.page.TableDataInfo;

/**
 * 智能柜Controller
 * 
 * @author ruoyi
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/system/stall")
public class StallController extends BaseController
{
    @Autowired
    private IStallService stallService;

    /**
     * 查询智能柜列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Stall stall)
    {
        startPage();
        List<Stall> list = stallService.selectStallList(stall);
        return getDataTable(list);
    }

    /**
     * 导出智能柜列表
     */
    @Log(title = "智能柜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Stall stall)
    {
        List<Stall> list = stallService.selectStallList(stall);
        ExcelUtil<Stall> util = new ExcelUtil<Stall>(Stall.class);
        util.exportExcel(response, list, "智能柜数据");
    }

    /**
     * 获取智能柜详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stallService.selectStallById(id));
    }

    /**
     * 新增智能柜
     */
    @Log(title = "智能柜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Stall stall)
    {
        return toAjax(stallService.insertStall(stall));
    }

    /**
     * 修改智能柜
     */
    @Log(title = "智能柜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Stall stall)
    {
        return toAjax(stallService.updateStall(stall));
    }

    /**
     * 删除智能柜
     */
    @Log(title = "智能柜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stallService.deleteStallByIds(ids));
    }
}
